import db_helper

def loadAllLotter():
    with db_helper.buildDbHelper() as db:
        #queryAllSql = " select * from WinningNumbers order by Id;"
        queryAllSql="select * from WinningNumbers where DrawDate >  DATE_ADD(CURDATE(),INTERVAL -30 DAY) and Period not in (select Period FROM Lotter) order by DrawDate;"
        records = db.executeQuerySql(queryAllSql)
        print(records) 
        for record in records:
            insertSql = f" insert into Lotter (Period,TypeCode,DrawDate) VALUES ('{record[2]}','1','{record[3]}'); "
            db.executeCommit(insertSql)
            for i in range(4,11):
                insertSql =f" insert into LotterNumbers (Period,Site,Number) VALUES ('{record[2]}','{i-3}','{record[i]}') ; "
                db.executeCommit(insertSql)


def main():
    loadAllLotter()


if __name__ == '__main__':
    main()
    print('all done')
